<?php 
namespace Weedo\Http;

/**
 * Flash class.
 * @link http://stackoverflow.com/questions/6021520/cookie-vs-session-based-flash-message
 * @date 2011-06-14
 */
class Flash
{
    static $counter = 0;
    static public function set($message){
        self::$counter++;
        setcookie("flash_{$counter}", $message, time() + 60 * 10);
    }
    
    
    static public function get(){
       $flashes = array();
       foreach($_COOKIE as $id => $value){
            if(strpos($id, "flash_") === 0){
                 $flashes[$id] = $value;
                 //clear flash and set expiration to 10 minutes in past
                 setcookie($id, "", time() * 60 * -10);
    
             }
      }
      return $flashes;
       //Input cleansing not included for brevity/clarity
    }
}